/**
 * Run test games to compare two Eval-functions / two search methods etc.
 */

import java.io.IOException;

import static java.lang.System.err;
import static java.lang.System.out;

public class DemoEvalComps {

    private static ComputerPlayer black;
    private static ComputerPlayer white;

    public static void main(String[] args) {
        if (args.length > 0 && args[0].equalsIgnoreCase("d")) {
            out.println("Test draw fix");
            testDrawFix();
        } else if (args.length > 0 && args[0].equalsIgnoreCase("i")) {
            out.println("Test iterative deepening");
            testIter();
        } else if (args.length > 0 && args[0].equalsIgnoreCase("q")) {
            out.println("Test quiescence");
            testQ();
        } else if (args.length > 0 && args[0].equalsIgnoreCase("h")) {
            out.println("Test history heuristic");
            testHH();
        } else if (args.length > 0 && args[0].equalsIgnoreCase("w")) {
            out.println("Who wins?");
            whoWins();
        } else if (args.length > 0 && args[0].equalsIgnoreCase("x")) {
            out.println("Who wins? (Simple eval)");
            whoWins2();
        } else {
            out.println("Compare eval classes");
            compareEvals();
        }

        Board board = null;
        if (args.length > 1) {
            String fileName = args[1];
            try {
                board = ColWhiskers.loadBoard(fileName);
            } catch (IOException e) {
                err.println("Couldn't load board from filename " + fileName);
                e.printStackTrace();
                System.exit(1);
            }
            if (board == null) {
                err.println("Couldn't parse board from filename " + fileName);
                System.exit(1);
            }

            if (!board.isSane()) {
                out.println("You have tried to load a board that violates the"
                            + " rules of the game. Exiting.");
                System.exit(1);
            }
        } else {
            board = new Board();
        }

        black.setPrintBestMoveValue(true);
        white.setPrintBestMoveValue(true);

        GameEngine.runGame(black, white, board);
    }

    public static void compareEvals() {
	black = new ABMiniMaxDrawFix(true,new EvalMaterialOnly(),10);
	white = new ABMiniMaxDrawFix(false,new NewEval(),10);
    }

    public static void testDrawFix() {
	black = new ABMiniMaxDrawFix(true,new EvalMaterialOnly(),10);
	white = new ABMiniMaxDrawFix(false,new EvalMaterialOnly(),10);
    }

    public static void testIter() {
	black = new IterABMiniMaxDrawFix(true,new EvalMaterialOnly(),6);
	white = new ABMiniMaxDrawFix(false,new EvalMaterialOnly(),6);
    }

    public static void testQ() {
        black = new QABMiniMaxDrawFix(true,new EvalMaterialOnly(),9);
        white = new ABMiniMaxDrawFix(false,new EvalMaterialOnly(),9);
    }

    public static void testHH() {
	black = new IterABMiniMaxDrawFix(true,new EvalMaterialOnly(),6);
	white = new HHIterABMiniMaxDrawFix(false,new EvalMaterialOnly(),6);
    }

    public static void whoWins() {
        black = new QABMiniMaxDrawFix(true,  new NewEval(), 10);
        white = new QABMiniMaxDrawFix(false, new NewEval(), 10);
    }

    public static void whoWins2() {
        black = new QABMiniMaxDrawFix(true,  new EvalMaterialOnly(), 10);
        white = new QABMiniMaxDrawFix(false, new EvalMaterialOnly(), 10);
    }
}
